# Maintainer: Adam Thiede <me@adamthiede.com>
# Co-Maintainer: Jenneron <jenneron@protonmail.com>
pkgname=linux-postmarketos-mediatek-mt8173
pkgver=6.12.9
pkgrel=0
pkgdesc="Mainline kernel fork for Mediatek MT8173 devices"
arch="aarch64"
_carch="arm64"
_flavor="${pkgname#linux-}"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
"
makedepends="
	bash
	bison
	findutils
	flex
	openssl-dev
	perl
	postmarketos-installkernel
	gmp-dev
	mpc1-dev
	mpfr-dev
	xz
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac
source="
	https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${pkgver//_/-}.tar.xz
	$_config
	fix-mmc-order.patch
"
builddir="$srcdir/linux-${_kernver//_/-}"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir/boot/dtbs"
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
3538c19b22f1810849e01ad7005f39b0c4e1e2de99f3168bb6a35ad9d51d7ec7b22a8203890e7b073bff83951f930245d5857a86cef80454800136a53047ff37  linux-6.12.9.tar.xz
d442faaff1a9352c36c81ccd01f6d5322a28a6df8f4e735b866611cd127576320e75a6aa3bb731a273f6d48933ad47e305602510b731158abc17dc98b89ac437  config-postmarketos-mediatek-mt8173.aarch64
c86f8dfc32165a32381d45a4c8b6811ebf43f01b5d8a48fbe227cf5084cfefe24b32264c1c150cb49115db4759a2d21ad48b37dcaac78367d226e9cc2a5ba849  fix-mmc-order.patch
"
